﻿<UserControl x:Class="Passwords.Views.PasswordView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:utils="clr-namespace:Passwords.Utils" xmlns:views="clr-namespace:Passwords.Views"
        xmlns:vm="clr-namespace:Passwords.ViewModels" xmlns:models="clr-namespace:Passwords.Models"
        xmlns:controls="clr-namespace:Passwords.Controls" xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:vr="clr-namespace:Passwords.ValidationRules"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="368"
        d:DesignWidth="574" Focusable="True">
    <UserControl.FocusVisualStyle>
        <Style/>
    </UserControl.FocusVisualStyle>
    <UserControl.Resources>
        <ControlTemplate TargetType="UserControl" x:Key="passwordViewTemplate">
            <Grid Margin="0,0,10,0" FocusManager.FocusedElement="{Binding ElementName=editName}" x:Name="grid"
            DataContext="{Binding SelectedPassword}">
                <Grid.Resources>
                    <Style TargetType="RadioButton" BasedOn="{StaticResource textRadioStyle}" />
                    <Style TargetType="Button" BasedOn="{StaticResource iconButtonStyle}" />

                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <!--Header:-->
                <Grid Grid.Row="0" Margin="10,5,0,-5">
                    <TextBlock Text="{Binding Name, FallbackValue=no password}" VerticalAlignment="Top" Margin="0,-15,20,20"
                    TextBlock.FontSize="24" TextBlock.FontWeight="Bold" >
                        <TextBlock.RenderTransform>
                            <TranslateTransform x:Name="translateName"/>
                        </TextBlock.RenderTransform>
                    </TextBlock>
                    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,-4,0" Orientation="Horizontal">
                        <Button Content="{Binding rs.LogoutBtn, Source={StaticResource locale}}" Style="{StaticResource radioLikeButtonStyle}"
                        Command="{x:Static vm:Commands.LogoutCommand}" />
                        <StackPanel.RenderTransform>
                            <TranslateTransform x:Name="translateLogout"/>
                        </StackPanel.RenderTransform>
                    </StackPanel>
                    <Grid.RenderTransform>
                        <TranslateTransform x:Name="translateHeader"/>
                    </Grid.RenderTransform>
                </Grid>

                <!--    Detail View-->
                <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled" x:Name="detailsView" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="False">
                    <Grid>
                        <ItemsControl x:Name="selectedCategories" HorizontalAlignment="Right" Margin="5,10,5,5" Focusable="False"
                        ItemsSource="{Binding Categories}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}" HorizontalAlignment="Right" FontSize="9"
                                    SnapsToDevicePixels="True" Opacity="0.60" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <ItemsControl x:Name="fieldList" Margin="10,6,10,5" Focusable="False" ItemsSource="{Binding Fields}"
                        ItemTemplate="{StaticResource fieldTemplate}" />
                    </Grid>
                    <ScrollViewer.RenderTransform>
                        <TranslateTransform x:Name="translateDetail"/>
                    </ScrollViewer.RenderTransform>
                </ScrollViewer>

                <!--Footer:-->
                <Border BorderThickness="0,1,0,0" Grid.Row="3" BorderBrush="{DynamicResource TransparentChromeBrush}">
                    <StackPanel x:Name="footerPanel"  Orientation="Horizontal" Margin="10,8,10,0"  HorizontalAlignment="Center">
                        <StackPanel.Resources>
                            <Style TargetType="Button" BasedOn="{StaticResource radioLikeButtonStyle}" />
                        </StackPanel.Resources>
                        <Button Content="{Binding rs.BackBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.PasswordsCommand}" >
                            <Button.RenderTransform>
                                <TranslateTransform x:Name="translateBack"/>
                            </Button.RenderTransform>
                        </Button>
                        <Separator Style="{StaticResource lineSepStyle}" />
                        <Button Content="{Binding rs.EditBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.EditPasswordCommand}" >
                            <Button.RenderTransform>
                                <TranslateTransform x:Name="translateEdit"/>
                            </Button.RenderTransform>
                        </Button>
                        <StackPanel.RenderTransform>
                            <TranslateTransform x:Name="footerTransform"/>
                        </StackPanel.RenderTransform>
                    </StackPanel>
                </Border>

            </Grid>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Password}">
                    <Setter Property="controls:FocusContainer.IsFocused" Value="true"/>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="40" To="0" Duration="0:0:0.15"
                                        Storyboard.TargetProperty="Y" Storyboard.TargetName="translateDetail">
                                    <DoubleAnimation.EasingFunction>
                                        <PowerEase Power="3"  EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation From="-40" To="0" Duration="0:0:0.2"
                                        Storyboard.TargetProperty="Y" Storyboard.TargetName="translateName">
                                    <DoubleAnimation.EasingFunction>
                                        <PowerEase Power="3"  EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation From="30" To="0" Duration="0:0:0.2"
                                        Storyboard.TargetProperty="X" Storyboard.TargetName="translateLogout">
                                    <DoubleAnimation.EasingFunction>
                                        <ExponentialEase Exponent="5" EasingMode="EaseOut"/>
                                        <!--<PowerEase Power="3"  EasingMode="EaseOut"/>-->
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation Storyboard.TargetName="footerTransform" Storyboard.TargetProperty="Y" From="80" To="0" Duration="0:0:0.25">
                                    <DoubleAnimation.EasingFunction>
                                        <ExponentialEase Exponent="5" EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation From="0" To="1" Duration="0:0:0.2"
                                        Storyboard.TargetProperty="Opacity" Storyboard.TargetName="grid">
                                    <DoubleAnimation.EasingFunction>
                                        <PowerEase Power="3" EasingMode="EaseOut" />
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Resources>
    <UserControl.InputBindings>
        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.PasswordsCommand}" />
    </UserControl.InputBindings>
    <UserControl.Style>
        <Style TargetType="UserControl">
            <!--<Setter Property="Template" Value="{StaticResource passwordViewTemplate}"/>-->
            <Setter Property="Focusable" Value="True" />
            <!--<Setter Property="controls:FocusContainer.FocusDelay" Value="0:0:0.5" />-->
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Password}" >
                    <Setter Property="Template" Value="{StaticResource passwordViewTemplate}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>
</UserControl>
